// 随机整数
export const RandomInt = (min: number, max: number): number => {
  return Math.floor((Math.random() * max) + min)
}

// 随机字符
// [upper] 是否使用大写
// [number] 是否使用数字
// [symbol] 是否使用字符
// [removeSimilar] 删除相似的字符
export const RandomStr = (len: number, ext: {
  upper?: boolean;
  number?: boolean;
  symbol?: boolean;
  removeSimilar?: boolean;
} = { upper: true, number: true, symbol: true, removeSimilar: true }): string => {
  let str = 'abcdefghijklopqrstuvwxyz'
  if (ext.upper) {
    str += str.toUpperCase()
  }
  if (ext.number) {
    str += '0123456789'
  }
  if (ext.symbol) {
    str += '~!@#$%^&*()_+-'
  }
  if (ext.removeSimilar) {
    str = str
      .replace(/O|I|S|Z|!/g, '')
  }
  let ret = ''
  for (let i = 0; i < len; i++) {
    ret += str[RandomInt(0, str.length - 1)]
  }
  return ret
}
